/*
 * A1_1.cpp
 *
 *  Created on: Feb 19, 2013
 *      Author: Anthony Varghese
 */

#include <string>

enum gender { boy, girl };

struct Data{
	short year;
	std::string name;
	double percent;
	gender sex;
};

class BabyNames {
public:
	BabyNames(){
		data[0] = { 1880, "Mary",	0.072381, girl };
		data[1] = {	1880, "Anna",	0.026678, girl };
		data[2] = {	1880, "Emma",	0.020521, girl };
		data[3] = {	1880, "Elizabeth",	0.019865, girl };
		data[4] = { 1880, "Minnie",	0.017888,  girl	};
		data[5] = { 1880, "John",	0.081541,  boy	};
		data[6] = {	1880, "William",0.080511,  boy	};
		data[7] = {	1880, "James",	0.050057,  boy	};
		data[8] = {	1880, "Charles", 0.045167, boy	};
		data[9] = { 1880, "George",	0.043292,  boy	};

		datasize = 10;
	}
	int getDataSize() const {
		return datasize;
	}
	const Data& get(int i) const {
		if (i>=0 && i < datasize)
			return data[i];
		throw OUT_OF_BOUNDS;
	}
	void sortByName(){

	}
	void sortByPopularity(){

	}
private:
	static const int MAX_DATA_SIZE = 20;
	Data data[MAX_DATA_SIZE];
	int datasize;
	static const int OUT_OF_BOUNDS = -1;
};

#include <iostream>
std::ostream& operator<<(std::ostream& os, const Data& d){
	os << d.name << " " << d.year << " " << d.percent << " " << d.sex;
	return os;
}
std::ostream& operator<<(std::ostream& os, const BabyNames& bn){
	os << "  BabyNames object " << std::endl;
	for (int i=0; i < bn.getDataSize(); i++ )
		os << "    " << (i+1) <<":  " << bn.get( i ) << std::endl;
	return os;
}


using namespace std;

int main(void){
	cout << "Baby names: " << endl;
	BabyNames names;
	cout << names;
	cout << "Sorted by popularity" << endl;
	names.sortByPopularity();
	cout << names;
	cout << "Sorted by name" << endl;
	names.sortByName();
	cout << names;
	cout << "... done!" << endl;
}
